/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.info.runninginfo;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import com.info.runninginfo.entity.ExceptionEntity;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ExceptionManager {
	public static String exception_xml(Context paramContext) {
		return paramContext.getApplicationInfo().dataDir + "/" + "exception_m_"
				+ System.currentTimeMillis() + ".xml";
	}

	public static String getCurrentDate() {
		return new SimpleDateFormat("yyyy-MM-dd   hh:mm:ss").format(new Date());
	}

	public static String getExceptionInfo(ExceptionEntity paramExceptionEntity) {
		if (paramExceptionEntity == null)
			return "";
		return paramExceptionEntity.getEid() + ", \""
				+ paramExceptionEntity.getClassName() + "\", \""
				+ paramExceptionEntity.getType() + "\", \""
				+ paramExceptionEntity.getMessage() + "\", \""
				+ paramExceptionEntity.getStack() + "\", \""
				+ paramExceptionEntity.getDate() + "\"";
	}

	public void saveException(Context paramContext, Class<?> paramClass,
			Exception paramException) {
		saveException(paramContext, paramClass.getName(), paramException);
	}

	public void saveException(Context paramContext, String paramString,
			Exception paramException) {
		if (paramException == null)
			return;
		String str = "\r\n\r\n";
		int i = paramException.getStackTrace().length;
		for (int j = 0;; ++j) {
			if (j >= i) {
				ExceptionEntity localExceptionEntity = new ExceptionEntity();
				localExceptionEntity.setEid(System.currentTimeMillis());
				localExceptionEntity.setClassName(paramString);
				localExceptionEntity.setMessage(paramException.getMessage());
				localExceptionEntity.setType(paramException.getClass()
						.getName());
				if ((!("The operation timed out".equals(localExceptionEntity
						.getMessage())))
						&& (!("Network unreachable".equals(localExceptionEntity
								.getMessage())))
						&& (!("No route to host".equals(localExceptionEntity
								.getMessage())))
						&& (!("The connection was reset"
								.equals(localExceptionEntity.getMessage())))
						&& (!(localExceptionEntity.getMessage()
								.contains("time out"))))
					;
				localExceptionEntity.setStack(str);
				localExceptionEntity.setDate(getCurrentDate());
				RunningInfo.outputRunningInfo(paramContext, "已发生异常，详细信息如下\r\n",
						getExceptionInfo(localExceptionEntity));
				if (Config.needDisplay)
					;
				RunningInfo.displayFile(paramContext, "信息提示，请选择软件查看\r\n"
						+ paramException.getMessage());
				return;
			}
			str = str + "at " + paramException.getStackTrace()[j].toString()
					+ "\r\n";
		}
	}
}